package com.dominator.utils.mail;

import com.dominator.utils.system.PropertiesLoader;
import microsoft.exchange.webservices.data.core.ExchangeService;
import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
import microsoft.exchange.webservices.data.core.service.item.EmailMessage;
import microsoft.exchange.webservices.data.credential.ExchangeCredentials;
import microsoft.exchange.webservices.data.credential.WebCredentials;
import microsoft.exchange.webservices.data.property.complex.MessageBody;

import java.net.URI;

public class OutlookEmailUtils {

    public static PropertiesLoader propertiesLoader = new PropertiesLoader("sysconfig.properties");



    public void sendEmail(String title) throws Exception {
        ExchangeService service = new ExchangerServiceSSLVerify(ExchangeVersion.Exchange2010_SP2);
        String userName = propertiesLoader.getProperty("mail_user");  //用户名
        String password = propertiesLoader.getProperty("mail_password"); //密码
        String domain = ""; //域
        String url = ""; //邮件服务器地址
        ExchangeCredentials credentials = new WebCredentials(userName, password, domain);
        service.setCredentials(credentials);
        service.setUrl(new URI("https://" + "邮箱服务器地址" + "/EWS/Exchange.asmx"));
        EmailMessage msg = new EmailMessage(service);
        msg.setSubject("标题");
        msg.setBody(MessageBody.getMessageBodyFromText("测试内容"));
        msg.getToRecipients().add("xxx@xx.com.cn"); //接受人
        msg.getCcRecipients().add("xxxx@xx.com.cn"); //抄送
        msg.send();  //发送现有电子邮件
    }





}
